/*!
 * Copyright (C) 2020 - All Rights Reserved by
 * @author : ZhaoYanbo
 * @email  : zyb920@hotmail.com
 * @created: 2020-10-31
 * @version: 1.0.0.0
 *
 */

#include "Widget.h"
#include <QListView>
#include "ListModel.h"
#include "ListDelegate.h"
#include <QHBoxLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    this->resize(600, 600);
    QListView *listW = new QListView(this);
    ListModel *model = new ListModel(listW);
    ListDelegate *delegate = new ListDelegate(listW);
    listW->setModel(model);
    listW->setItemDelegate(delegate);
    listW->setFrameShape(QFrame::NoFrame);
#if 1
    //listW->setMovement(QListView::Free);
    listW->setViewMode(QListView::IconMode);
    listW->setResizeMode(QListView::Adjust );
#endif

    QHBoxLayout *hlay = new QHBoxLayout(this);
    hlay->addWidget(listW);

    char c = 'a';
    char tmp;
    for (int i=0; i<26; ++i) {
        tmp = c+i;
        Data *data = new Data();
        data->name = "Section: " + QString(tmp);
        data->isHead = true;
        for(int j=0; j<9; ++j)
        {
            Data *subData = new Data(data);
            subData->name = QString("%1: %2").arg(tmp).arg(j+1);
            data->subs.append(subData);
        }
        model->append(data);
    }
}

Widget::~Widget()
{
}

